package com.yanqu.road.dao.impl.activity.evefeast;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.evefeast.config.EveFeastAchieveConfig;
import com.yanqu.road.entity.activity.evefeast.config.EveFeastBuffConfig;
import com.yanqu.road.entity.activity.evefeast.config.EveFeastMissionConfig;
import com.yanqu.road.entity.activity.evefeast.config.EveFeastObjectConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class EveFeastConfigDaoImpl extends TempDao {
    public Map<Integer, EveFeastObjectConfig> getEveFeastObjectConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_s_activity_evefeast_object where activityId=?";
        Map<Integer, EveFeastObjectConfig> dataMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                EveFeastObjectConfig data = new EveFeastObjectConfig(rs.getInt("activityId"), rs.getInt("objectId"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setQuality(rs.getInt("quality"));
                data.setBaseScore(rs.getInt("baseScore"));
                data.setType(rs.getInt("type"));
                data.setWeight(rs.getString("weight"));
                data.setConditionParam(rs.getString("conditionParam"));
                data.setEffectParam(rs.getString("effectParam"));
                data.setSect(rs.getInt("sect"));
                data.setTieItem(rs.getString("tieItem"));
                data.setButtonInfo(rs.getString("buttonInfo"));
                data.setLimitNum(rs.getInt("limitNum"));

                dataMap.put(data.getObjectId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public Map<Integer, EveFeastBuffConfig> getEveFeastBuffConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_s_activity_evefeast_buff where activityId=?";
        Map<Integer, EveFeastBuffConfig> dataMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                EveFeastBuffConfig data = new EveFeastBuffConfig(rs.getInt("activityId"), rs.getInt("greetingId"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setQuality(rs.getInt("quality"));
                data.setWeight(rs.getString("weight"));
                data.setWeightChange(rs.getString("weightChange"));
                data.setSkill(rs.getString("skill"));
                data.setIcon(rs.getString("icon"));
                data.setButtonInfo(rs.getString("buttonInfo"));

                dataMap.put(data.getGreetingId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public Map<Integer, EveFeastMissionConfig> getEveFeastMissionConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_s_activity_evefeast_mission where activityId=?";
        Map<Integer, EveFeastMissionConfig> dataMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                EveFeastMissionConfig data = new EveFeastMissionConfig(rs.getInt("activityId"), rs.getInt("id"));
                data.setMission(rs.getInt("mission"));
                data.setTurn(rs.getInt("turn"));
                data.setRound(rs.getInt("round"));
                data.setCondition(rs.getInt("condition"));
                data.setWeightParam(rs.getString("weightParam"));
                data.setBuffWeightParam(rs.getString("buffWeightParam"));
                data.setExItem(rs.getString("exItem"));

                dataMap.put(data.getTurnId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public Map<Integer, EveFeastAchieveConfig> getEveFeastAchieveConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_s_activity_evefeast_achieve where activityId=?";
        Map<Integer, EveFeastAchieveConfig> dataMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                EveFeastAchieveConfig data = new EveFeastAchieveConfig(rs.getInt("activityId"), rs.getInt("id"));
                data.setType(rs.getInt("type"));
                data.setCondition(rs.getString("condition"));
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}
